package com.rest.demo.concurrent;

import com.rest.demo.functional.concurrent.ConcurrentUtils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

/**
 * @author Administrator
 * @decription
 * @Date 2018-02-01 11:14
 */
public class ThreadPoolDemo {

    public static void main(String[] args) {
        ExecutorService threadPool = Executors.newFixedThreadPool(10);
        IntStream.range(0,10).forEach(i -> threadPool.execute(() -> {
            IntStream.range(0,5).forEach(j -> {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()
                        + " looping of " + j + " for task of " + i);
            });
        }));
        ConcurrentUtils.stop(threadPool);
    }
}
